package com.fishingwithme.infrastructure.utils;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.mail.*;

@Setter
@Getter
public class EmailSenderFactory {

    private String emailHost;
    private int emailPort;
    private String emailAddress;
    private String emailPassword;

    private boolean sslEnabled;

    private boolean tlsEnabled;

    public SimpleEmail createSimpleEmail() throws EmailException {
        SimpleEmail email = new SimpleEmail();
        this.configureEmail(email);
        return email;
    }


    private void configureEmail(Email email) {
        email.setHostName(emailHost);
        email.setSmtpPort(emailPort);
        email.setAuthenticator(new DefaultAuthenticator(emailAddress, emailPassword));
        email.setSSLOnConnect(sslEnabled);
        email.setStartTLSEnabled(tlsEnabled);
        email.setCharset(EmailConstants.UTF_8);
    }

}
